package com.gl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gl.entity.EduCourse;
import com.gl.entity.EduTeacher;
import com.gl.mapper.EduTeacherMapper;
import com.gl.service.EduCourseService;
import com.gl.service.EduTeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-12-14
 */
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements EduTeacherService {

    @Autowired
    private EduCourseService courseService;
    //分页查询讲师
    @Override
    public Map<String, Object> getPageList(long current, long size) {
        Page<EduTeacher> page = new Page<>(current,size);
        //分页查询
        baseMapper.selectPage(page,null);
        //把数据存入map中
        Map<String,Object> map = new HashMap<>();
        map.put("list",page.getRecords());//分页集合
        map.put("total",page.getTotal());//总记录数
        map.put("size",page.getSize());//每页大小
        map.put("current",page.getCurrent());//当前页
        map.put("pages",page.getPages());//总页数
        map.put("hasNext",page.hasNext());//是否有下一页
        map.put("hasPrevious",page.hasPrevious());//是否有上一页

        return map;
    }
    //根据讲师id查询讲师详情
    @Override
    public Map<String, Object> getDetailById(String id) {
        Map<String,Object> map = new HashMap<>();
        //根据讲师id查询讲师
        EduTeacher teacher = baseMapper.selectById(id);
        //根据讲师id查询所讲课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",id);
        List<EduCourse> listCourse = courseService.list(wrapper);

        map.put("teacher",teacher);
        map.put("listCourse",listCourse);
        return map;
    }
}
